package com.adong.test.oneToOne.foreign;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * @author adong
 */
public class ForeignTest {
    private SessionFactory sessionFactory;
    private Session session;
    private Transaction transaction;

    @Before
    public void init() {
        Configuration configuration = new Configuration().configure();
        sessionFactory = configuration.buildSessionFactory();
        session = sessionFactory.openSession();
        transaction = session.beginTransaction();
    }

    @After
    public void destroy() {
        transaction.commit();
        session.close();
        sessionFactory.close();
    }

    @Test
    public void Test() {

        Department department = new Department();
        department.setName("清洁部");

        Manager manager = new Manager();
        manager.setName("蔡徐坤");
        manager.setAge(100);

        department.setManager(manager);
        manager.setDepartment(department);

        session.save(department);
        session.save(manager);

    }
}
